#include <boost/test/unit_test.hpp>

#include <JuegoLib/Scheduler.h>

BOOST_AUTO_TEST_SUITE( Sistema_De_Tareas_Tests )


class TestTask : public ITask
{
public:

	int n;
	bool b;
	
	TestTask() : n(0), b(true) {}

	bool Execute()
	{
		n++;
		return b;
	}
};


BOOST_AUTO_TEST_CASE( SchedulerClassInit )
{
	Scheduler sch;
	sch.Initialize(1000);
}

BOOST_AUTO_TEST_CASE( Sist_Tareas_Basico )
{
	Scheduler sch;
	sch.Initialize(1000);

	TestTask * tt = new TestTask;
	ITask::Ptr tsk(tt);

	sch.AddTask(tsk, 500, 3);

	BOOST_REQUIRE(tt->n == 0);

	sch.Update(250);

	BOOST_REQUIRE(tt->n == 0);

	sch.Update(250);

	BOOST_REQUIRE(tt->n == 1);

	sch.Update(500);

	BOOST_REQUIRE(tt->n == 2);

	sch.Update(250);
	sch.Update(300);

	BOOST_REQUIRE(tt->n == 3);

	sch.Update(500);

	BOOST_REQUIRE(tt->n == 3);
}


BOOST_AUTO_TEST_CASE( Sist_Tareas_Determ )
{
	Scheduler sch;
	sch.Initialize(1000);

	TestTask * tt = new TestTask;
	ITask::Ptr tsk(tt);

	sch.AddTask(tsk, 500, 3);

	sch.Update(500*4);
	sch.Update(1);
	sch.Update(1);
	sch.Update(1);

	BOOST_REQUIRE(tt->n == 3);

	sch.Update(2000);

	BOOST_REQUIRE(tt->n == 3);
}


BOOST_AUTO_TEST_CASE( Sist_Tareas_Autofinalizacion )
{
	Scheduler sch;
	sch.Initialize(1000);

	TestTask * tt = new TestTask;
	ITask::Ptr tsk(tt);

	sch.AddTask(tsk, 500, 3);

	tt->b = false;

	sch.Update(500);

	BOOST_REQUIRE(tt->n == 1);

	sch.Update(502);

	BOOST_REQUIRE(tt->n == 1);
}




BOOST_AUTO_TEST_SUITE_END()